<?php
if(!defined('ADMIN')){
	exit('Access Denied');
}


$page = !($_POST['pageNum'])?'1':intval($_POST['pageNum']);
$pagesize= !($_POST['numPerPage'])?'20':intval($_POST['numPerPage']);


if(empty($pagesize)){
    $pagesize=20;
}
$frmnum=($page-1)*$pagesize;
$orderField=trim($_POST["orderField"]);
$orderDirection=trim($_POST["orderDirection"]);
if(empty($orderField)){
    $orderField="id";
}
if(empty($orderDirection)){
    $orderDirection="desc";
}
if($orderField<>""){
    $order=" order by $orderField ".$orderDirection;
}else{
    $order=" order by id desc";
}

$q=trim($_POST['q']);
$mtype=trim($_POST["mtype"]);
$metcatid=trim($_POST["metcatid"]);
if(isset($_POST['mtype']) && $_POST['mtype']!=0){
	$parent_id=$_POST['mtype'];
	$where=' status=1  and mtype="'.$parent_id.'"';
}
else{
    $where=' status=1';
}
if($q<>""){
    
    $where.=" and title like '%".$q."%'";
}
if(!empty($mtype)){
    
    $where.=" and mtype=".$mtype;
    
}
if(!empty($metcatid)){
     $where.=" and metcatid=".$metcatid;
    
}
$total=$ezhand->count("material",$where);
$row=$ezhand->select_all("material",'*',''.$where.' '.$order.' limit '.$frmnum.','.$pagesize);

?>